/**
  ******************************************************************************
  * @file   util.c
  * @author Administrator
  * @since  2024/7/30
  *
  * @brief  Hardware/Peripheral driver of Xxx(Hardware/Simulation-Implemented).
  *
  ******************************************************************************
  */
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <stdarg.h>
#include "util.h"

bool start_with(char *src, char *prefix) {
    if (src == NULL || prefix == NULL) return false;

    const uint8_t prefix_len = strlen(prefix);
    if (prefix_len > strlen(src)) return false;

    uint8_t idx = 0;
    while (*prefix != '\0') {
        if (*src++ == *prefix++) idx++;
        else break;
    }

    return prefix_len == idx;
}

int split(char *src, const char *delim, char **result) {
    char *token;
    int idx = 0;

    token = strtok(src, delim);

    while (token != NULL) {
        *result++ = token;
        idx++;
        token = strtok(NULL, delim);
    }

    return idx;
}

